# -*- coding: utf-8 -*-

################################################################################
## Form generated from reading UI file 'mainwindow.ui'
##
## Created by: Qt User Interface Compiler version 6.0.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################

from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from model.Search import search_music
from model.Download import download_music
import os
from functools import partial


Path = ""


def play_music(tup_args):
        music_id, music_name, path = tup_args
        print(music_name, music_id, Path)
        download_music(music_id, music_name, Path)
        io_addr = path.replace('\\', '\\\\')
        os.system(io_addr + '\\music' + f"\\{music_name}.mp3")


def download_button(tup_args):
    music_id, music_name, path = tup_args
    print(music_name, music_id, Path)
    download_music(music_id, music_name, Path)


class Ui_MainWindow(object):

    def setupUi(self, MainWindow):
        if not MainWindow.objectName():
            MainWindow.setObjectName(u"MainWindow")
        MainWindow.resize(383, 512)
        MainWindow.setStyleSheet(u"background:rgb(255, 253, 249);")
        self.centralwidget = QWidget(MainWindow)
        self.centralwidget.setObjectName(u"centralwidget")
        self.pushButton = QPushButton(self.centralwidget)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(310, 50, 61, 31))
        self.pushButton.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(178, 255, 250);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.lineEdit = QLineEdit(self.centralwidget)
        self.lineEdit.setObjectName(u"lineEdit")
        self.lineEdit.setGeometry(QRect(10, 50, 281, 31))
        self.lineEdit.setStyleSheet(u"background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";")
        self.lineEdit_2 = QLineEdit(self.centralwidget)
        self.lineEdit_2.setObjectName(u"lineEdit_2")
        self.lineEdit_2.setGeometry(QRect(10, 9, 281, 31))
        self.lineEdit_2.setStyleSheet(u"background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";")
        self.pushButton_2 = QPushButton(self.centralwidget)
        self.pushButton_2.setObjectName(u"pushButton_2")
        self.pushButton_2.setGeometry(QRect(310, 10, 61, 31))
        self.pushButton_2.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(178, 255, 250);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.pushButton_3 = QPushButton(self.centralwidget)
        self.pushButton_3.setObjectName(u"pushButton_3")
        self.pushButton_3.setGeometry(QRect(10, 110, 301, 41))
        self.pushButton_3.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(200, 255, 199);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.pushButton_4 = QPushButton(self.centralwidget)
        self.pushButton_4.setObjectName(u"pushButton_4")
        self.pushButton_4.setGeometry(QRect(330, 110, 41, 41))
        self.pushButton_4.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 20px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(255, 148, 148);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.pushButton_5 = QPushButton(self.centralwidget)
        self.pushButton_5.setObjectName(u"pushButton_5")
        self.pushButton_5.setGeometry(QRect(10, 170, 301, 41))
        self.pushButton_5.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(200, 255, 199);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.pushButton_6 = QPushButton(self.centralwidget)
        self.pushButton_6.setObjectName(u"pushButton_6")
        self.pushButton_6.setGeometry(QRect(330, 170, 41, 41))
        self.pushButton_6.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 20px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(255, 148, 148);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}")
        self.pushButton_7 = QPushButton(self.centralwidget)
        self.pushButton_7.setObjectName(u"pushButton_7")
        self.pushButton_7.setGeometry(QRect(10, 230, 301, 41))
        self.pushButton_7.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(200, 255, 199);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.pushButton_8 = QPushButton(self.centralwidget)
        self.pushButton_8.setObjectName(u"pushButton_8")
        self.pushButton_8.setGeometry(QRect(330, 230, 41, 41))
        self.pushButton_8.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 20px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(255, 148, 148);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}")
        self.pushButton_9 = QPushButton(self.centralwidget)
        self.pushButton_9.setObjectName(u"pushButton_9")
        self.pushButton_9.setGeometry(QRect(10, 290, 301, 41))
        self.pushButton_9.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(200, 255, 199);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.pushButton_10 = QPushButton(self.centralwidget)
        self.pushButton_10.setObjectName(u"pushButton_10")
        self.pushButton_10.setGeometry(QRect(330, 290, 41, 41))
        self.pushButton_10.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 20px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(255, 148, 148);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}")
        self.pushButton_11 = QPushButton(self.centralwidget)
        self.pushButton_11.setObjectName(u"pushButton_11")
        self.pushButton_11.setGeometry(QRect(10, 350, 301, 41))
        self.pushButton_11.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 8px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(200, 255, 199);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}\n"
"")
        self.pushButton_12 = QPushButton(self.centralwidget)
        self.pushButton_12.setObjectName(u"pushButton_12")
        self.pushButton_12.setGeometry(QRect(330, 350, 41, 41))
        self.pushButton_12.setStyleSheet(u"QPushButton{color: rgb(0, 0, 0);background:rgb(255, 253, 249);border:1px solid grey; border-radius: 20px;font: 9pt \"Comic Sans MS\";}\n"
"QPushButton:hover{border-color:rgb(255, 148, 148);background:rgb(255, 253, 244);}\n"
"QPushButton:pressed{border-color:gray;background:rgb(255, 250, 234)}")
        self.label = QLabel(self.centralwidget)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(100, 440, 171, 21))
        self.label.setStyleSheet(u"font: 75 9pt \"Anonymous Pro for Powerline\";")
        self.label_2 = QLabel(self.centralwidget)
        self.label_2.setObjectName(u"label_2")
        self.label_2.setGeometry(QRect(20, 410, 151, 21))
        self.label_2.setStyleSheet(u"font: 9pt \"Comic Sans MS\";")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QMenuBar(MainWindow)
        self.menubar.setObjectName(u"menubar")
        self.menubar.setGeometry(QRect(0, 0, 383, 21))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QStatusBar(MainWindow)
        self.statusbar.setObjectName(u"statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        self.button_list = [
            [self.pushButton_3, self.pushButton_4],
            [self.pushButton_5, self.pushButton_6],
            [self.pushButton_7, self.pushButton_8],
            [self.pushButton_9, self.pushButton_10],
            [self.pushButton_11, self.pushButton_12],
        ]

        QMetaObject.connectSlotsByName(MainWindow)
    # setupUi

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"MainWindow", None))
        self.pushButton.setText(QCoreApplication.translate("MainWindow", u"Search", None))
        self.lineEdit.setText("")
        self.lineEdit_2.setText("")
        self.lineEdit.setPlaceholderText(QCoreApplication.translate("MainWindow", u"Search something . . . ", None))
        self.lineEdit_2.setPlaceholderText(QCoreApplication.translate("MainWindow", u"~/music", None))
        self.pushButton_2.setText(QCoreApplication.translate("MainWindow", u"Set", None))
        self.pushButton_3.setText("")
        self.pushButton_4.setText(QCoreApplication.translate("MainWindow", u"🎵", None))
        self.pushButton_5.setText("")
        self.pushButton_6.setText(QCoreApplication.translate("MainWindow", u"🎵", None))
        self.pushButton_7.setText("")
        self.pushButton_8.setText(QCoreApplication.translate("MainWindow", u"🎵", None))
        self.pushButton_9.setText("")
        self.pushButton_10.setText(QCoreApplication.translate("MainWindow", u"🎵", None))
        self.pushButton_11.setText("")
        self.pushButton_12.setText(QCoreApplication.translate("MainWindow", u"🎵", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"Cloud Music Installer 1.0", None))
        self.label_2.setText(QCoreApplication.translate("MainWindow", u"No task...", None))

        self.pushButton_3.setVisible(False)
        self.pushButton_4.setVisible(False)
        self.pushButton_5.setVisible(False)
        self.pushButton_6.setVisible(False)
        self.pushButton_7.setVisible(False)
        self.pushButton_8.setVisible(False)
        self.pushButton_9.setVisible(False)
        self.pushButton_10.setVisible(False)
        self.pushButton_11.setVisible(False)
        self.pushButton_12.setVisible(False)

        self.pushButton.clicked.connect(self.search_button)
        self.pushButton_2.clicked.connect(self.set_path)
        global Path
        Path = os.getcwd()
        print('set success', Path)
    # retranslateUi

    def set_path(self):
        global Path
        Path = self.lineEdit_2.text()
        self.lineEdit_2.setPlaceholderText(QCoreApplication.translate("MainWindow", Path, None))

    def search_button(self):
        music_name = self.lineEdit.text()
        music_list = search_music(music_name)
        if len(music_list) <= 5:
            for inx, music in enumerate(music_list[:]):
                self.button_list[inx][0].setText(f"{music['name']}-{music['artists'][0]['name']}-{music['id']}")
                self.button_list[inx][0].setVisible(True)
                self.button_list[inx][1].setVisible(True)
                self.button_list[inx][0].clicked.connect(partial(download_button, (music['id'], music['name'],
                                                                                  Path)))
                self.button_list[inx][1].clicked.connect(partial(play_music, (music['id'], music['name'],
                                                                                  Path)))
        else:
            for inx, music in enumerate(music_list[:5]):
                self.button_list[inx][0].setText(f"{music['name']}-{music['artists'][0]['name']}-{music['id']}")
                self.button_list[inx][0].setVisible(True)
                self.button_list[inx][1].setVisible(True)
                self.button_list[inx][0].clicked.connect(partial(download_button, (music['id'], music['name'],
                                                                                  Path)))
                self.button_list[inx][1].clicked.connect(partial(play_music, (music['id'], music['name'],
                                                                                  Path)))
